package GDoc::Job::Fetch::US::Legi::CRS;

use Moose;

extends 'GDoc::Job::Fetch';

sub should_run { 
    return 0;
}

sub run { 
    # this class does not do anything itself;
    # it is just a parent class for common 
    # functionality in the CRS::* subclasses

    shift->logger->info( "Nothing to do." );
}


sub _fetch_pdf { 
    my $self = shift;
    my %data = %{ $self->data };

    my $mech = $self->_mech;

    $self->logger->info( "Fetching PDF $data{pdf_link}" );

    eval { 
        $mech->get( $data{pdf_link} );
    };


    # some of these are 404s :(
    if ( my $err = $@ ) { 
        $self->logger->error( "PDF link $data{pdf_link} returned status " . $mech->status );
    }

    my $key = sprintf( "us/legi/crs/CRS-%s.pdf", $data{num} );
    $self->logger->info( "Storing $data{pdf_link} --> $key" );

    $self->store_pdf( key      => $key,
                      data     => $mech->response->content,
                      filename => sprintf( 'CRS-%s.pdf', $data{num} ),
                      meta     => { description  => $data{desc},
                                    identifier   => 'CRS-' . $data{num}
                                  }
                    );
}



1;
